<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app"></div>
</body>
<script>
    // let str='ab1c'
    //let reg=/^\w+$/
    // console.log(reg.test(str)) //true
    // console.log(reg.exec(str)) //index,[]
    console.log("------------search------------") //返回匹配字符串的下标
    let str = 'hello kgc'
    console.log(str.search(/kgc/)); //6
    console.log(str.search(/KGC/)); //-1
    console.log(str.search(/KGC/i)); //6

    console.log("------------match------------")//返回匹配字符串数组 g全局标志
    let str1 = "1 and 2 and 3"
    console.log(str1.match(/\d/));//[1]
    console.log(str1.match(/kgc/));//null
    console.log(str1.match(/\d/g));//["1", "2", "3"]

    console.log("-----------replace-------------")
    let str2 = "hello kgc! hello kgc!"
    console.log(str2.replace(/kgc/g, "web19"))


    console.log("-----------split-------------")
    let str3 = "hello kgc! hello kgc!"
    //分割后保存4个元素
    console.log(str3.split(/kgc/, 4))
</script>

</html>